#include <iostream>
#include <unistd.h>
#include <pthread.h>
using namespace std;

void* ThreadRoutine(void* args){
    int i = 0;
    while(true){
        cout << "child thread pid : " << getpid() << " name : " << (char*)args << endl;
        sleep(1);
        if(i++ == 5) break;
    }
    cout << "New thread exiting ..." << endl;
    pthread_exit((void*)15);                    // 使用方式：在线程所执行的函数中使用！区别于：pthread_cancel 函数！
}


int main(){

    pthread_t tid;
    pthread_create( &tid, nullptr, ThreadRoutine, (void*)"Thread Exit");

    // 获取返回
    int* ret = nullptr;
    pthread_join( tid , (void**)&ret );
    cout << "The child return : ret = " << (long int)ret << endl;   // 注意此处返回值的转换类型！

    return 0;
}